package Euler427;

import java.util.*;
import ReusableCode.SetLogic;

public class NSequences {
	public static void main(String[] args) {
		for(int n = 1; n <= 15; n++)
		{
			long nn = (long) Math.pow(n, n); 
			long nums[] = SetLogic.getContiguousSums(n);
			long sum = 0;
			
			//Get f(x)
			for(int i = 0; i < nums.length; i++)
			{
				sum += nums[i] * (i+1);
			}
			
			System.out.println("N is: " + n);
			System.out.println("Total number of sets is: " + nn);
			System.out.println("f(x) is: " + sum);
			
			String sums = "Number of contiguous values: {";
			String prob = "Probability of contiguous values: {";
			for(int i = 0; i < nums.length; i++)
			{
				//Handle the string.
				if (i < (nums.length)-1)
				{
					sums += (i+1) + ":" + nums[i] + ", ";
					prob += "P(" + (i+1) + "):" + (nums[i]/n) + "/" + (nn/n) + "(" + ((float)(nums[i]/n)/(nn/n)) + ")" + ", ";
				}
				else
				{
					sums += (i+1) + ":" + nums[i] + "}";
					prob += "P(" + (i+1) + "):" + (nums[i]/n) + "/" + (nn/n) + "(" + ((float)(nums[i]/n)/(nn/n)) + ")" + "}";
				}
			}
			
			System.out.println(sums);
			System.out.println(prob);
			System.out.println();
		}
		/*for(int n = 1; n <= 8; n++)
		{
			System.out.println("N is: " + n);
			long nn = (long) Math.pow(n, n);
			long sum = 0;
			
			ArrayList<int[]> sets = SetLogic.generateSets(n);
			int nums[] = new int[n];
			
			for(int i = 0; i < nums.length; i++)
			{
				nums[i] = 0;
			}
			
			for(int i = 0; i < sets.size(); i++)
			{
				String setString = "{";
				int set[] = sets.get(i);
				int count = 0, num = 0, max = 1;
				
				for(int j = 0; j < set.length; j++)
				{
					//Handle the string.
					if (j < (set.length)-1)
					{
						setString += set[j] + ", ";
					}
					else
					{
						setString += set[j] + "}";
					}
					
					//Handle the series.
					if(set[j] == num)
					{
						count++;
						if(count>max)
						{
							max = count;
						}
					}
					else
					{
						count=1;
						num = set[j];
					}
				}
				nums[max-1] = nums[max-1]+1;
				sum += max;
				//System.out.println(setString + " Longest chain has a length of: " + max);
			}
			
			System.out.println("Total number of sets is: " + sets.size());
			System.out.println("f(x) is: " + sum);
			
			String sums = "Number of contiguous values: {";
			String prob = "Probability of contiguous values: {";
			for(int i = 0; i < nums.length; i++)
			{
				//Handle the string.
				if (i < (nums.length)-1)
				{
					sums += (i+1) + ":" + nums[i] + ", ";
					prob += "P(" + (i+1) + "):" + (nums[i]/n) + "/" + (nn/n) + "(" + ((float)(nums[i]/n)/(nn/n)) + ")" + ", ";
				}
				else
				{
					sums += (i+1) + ":" + nums[i] + "}";
					prob += "P(" + (i+1) + "):" + (nums[i]/n) + "/" + (nn/n) + "(" + ((float)(nums[i]/n)/(nn/n)) + ")" + "}";
				}
			}
			
			System.out.println(sums);
			System.out.println(prob);
			System.out.println();
		}*/
	}
}
